package day06;

public class Demo02 {
    static int n = 0;
    public static void main(String[] args) throws InterruptedException {
        /*
         * 没有锁时候, 3线程累计一个整数
         */
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for (int i=0; i<20000; i++) {
                    n++;
                }
                System.out.println("T1 OK");
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                for (int i=0; i<20000; i++) {
                    n++;
                }
                System.out.println("T2 OK");
            }
        };
        t2.start();
        Thread t3 = new Thread(){
            @Override
            public void run() {
                for (int i=0; i<20000; i++) {
                    n++;
                }
                System.out.println("T3 OK");
            }
        };
        t3.start();
        Thread.sleep(1000);
        System.out.println(n);
    }
}
